/* Yet Another Experimental Software Renderer
 *
 * Copyright (c) 2010 Pawel "Hery" Dziepak
 */

#include "texture_sampler.h"

using namespace yaesr;

color point_sampler::get_color(vec2 coord) {
	Assert(tex != NULL);

	return tex->get_pixel(int(coord.x * tex->get_width()), int(coord.y * tex->get_height()));
}

color bilinear_sampler::get_color(vec2 coord) {
	Assert(tex != NULL);

	return (tex->get_pixel(int(coord.x * tex->get_width()), int(coord.y * tex->get_height()))
		+ tex->get_pixel(int(coord.x * tex->get_width() + 1), int(coord.y * tex->get_height()))
		+ tex->get_pixel(int(coord.x * tex->get_width() - 1), int(coord.y * tex->get_height()))
		+ tex->get_pixel(int(coord.x * tex->get_width()), int(coord.y * tex->get_height() + 1))
		+ tex->get_pixel(int(coord.x * tex->get_width()), int(coord.y * tex->get_height() - 1))
		+ tex->get_pixel(int(coord.x * tex->get_width() + 1), int(coord.y * tex->get_height() + 1))
		+ tex->get_pixel(int(coord.x * tex->get_width() - 1), int(coord.y * tex->get_height() - 1))
		+ tex->get_pixel(int(coord.x * tex->get_width() + 1), int(coord.y * tex->get_height() - 1))
		+ tex->get_pixel(int(coord.x * tex->get_width() - 1), int(coord.y * tex->get_height() + 1))) / 9.0;
}
